<template>
  <div class="avatar" :style="style" @tap.stop="goUser">
    <img :src="user.avatar_url" alt="用户头像">
  </div>
</template>

<script>
  import {ObjStyle} from '../common/js/base'

  export default {
    name: 'avatar',
    props: ['user', 'size'],
    data() {
      return {}
    },
    methods: {
      goUser() {
        wx.navigateTo({
          url: this.href
        })
      }
    },
    computed: {
      href() {
        return '/pages/user/main?id=' + this.user.loginname
      },
      style() {
        if (!this.size) return ''
        else {
          let style = {}
          if (this.size) {
            style['width'] = `${this.size}px`
            style['height'] = `${this.size}px`
          }
          return ObjStyle(style)
        }
      }
    },
    async onLoad() {
    }
  }
</script>

<style lang="scss" scoped>
  .avatar{
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 50%;
    overflow: hidden;
    img{
      width: 100%;
      height: 100%;
    }
  }
</style>
